﻿using LxBasic;

namespace LxLESS
{
    public class BiCGStabGlobal
    {
        public static double rho;//r dot r0可能正可能负数，没必要去除以数量
        public static double alpha;
        public static double omega;
        public static double beta;
        protected static bool GetIsBreak(double d)
        {
            return Math.Abs(d) < 1e-50;
        }
        public static bool Initialize_Step2()
        {
            rho = 1;
            alpha = 1;
            omega = 1;
            Cal_rhobeta();
            return GetIsNeedBreak();
        }
        public static bool GetIsNeedBreak()
        {
            if (GetIsBreak(rho)) return true;
            if (GetIsBreak(omega)) return true;
            return false;
        }
        public static void Cal_rhobeta()//1.2
        {
            (double rho_new, double sum2, double sum3) = ThreadsMath.MemoryRecallClear();
            beta = (rho_new / rho) * (alpha / omega);
            rho = rho_new;
        }
        public static bool Cal_alpha()//5.2
        {
            (double r0v, double sum2, double sum3) = ThreadsMath.MemoryRecallClear();
            if (GetIsBreak(r0v)) return true;
            alpha = rho / r0v;
            return false;
        }
        public static bool Cal_omega()//9.2
        {
            (double ts, double tt, double sum3) = ThreadsMath.MemoryRecallClear();
            if (GetIsBreak(tt)) return true;
            omega = ts / tt;
            return false;
        }
    }
}
